<template>
  <div class="my-tab-bar">
    <!-- 第一步：接收父组件传递的数据渲染底部导航栏 -->
    <div
      class="tab-item"
      :class="{ current: Currentindex === index }"
      v-for="(item, index) in arr"
      :key="index"
      @click="CurrentIndex(index)"
    >
      <!-- 图标 -->
      <!-- <span class="iconfont icon-shangpinliebiao"></span> -->
      <!-- 1.1动态绑定字体图标默认为true都显示[]是是属性名--传入是一个对象true认为有这个类名 -->
      <!-- <span class="iconfont" :class="{[item.iconText]:true}"></span> -->
      <!-- 方法二：传入字符串 -->
      <span class="iconfont" :class="item.iconText"></span>
      <!-- 文字 -->
      <span>{{ item.text }}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    arr: {
      type: Array,
      required: true,
      //1.2校验数据的长度如果长度在2-5之间返回true，否则返回false
      validator(val) {
        if (val.length < 2 || val.length > 5) {
          console.error('数据长度必须在2-5之间')
          return false
        }
        return true
      },
    },
  },
  data() {
    return {
      Currentindex: null,
    }
  },
  methods: {
    CurrentIndex(index) {
    this.Currentindex=index
    this.$emit('changeCom',index)
    },
  },
}
</script>

<style lang="less" scoped>
.my-tab-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: white;
  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}

.current {
  color: #1d7bff;
}
</style>
